package com.xdl.moudle.utils.util;

import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

/**
 * 正则验证工具类
 * @author xiazhengjiao
 * @date 2017年9月1日
 */
public class RegexUtil {

    private static final Pattern MOBILE_PHONE_PATTERN = Pattern.compile("^(13|15)[0-9]{9}$");

    private static final Pattern ZIP_CODE_PATTERN = Pattern.compile("^\\d{6}$");
    
    private static final String URL_CUT=".*\\/\\/([^\\?]*).*";

    /**
     * 判断是否是手机号码
     * @param phone
     * @return
     */
    public static boolean isMobilePhone(String phone) {
        return StringUtils.isBlank(phone) ? false : MOBILE_PHONE_PATTERN.matcher(phone).matches();
    }

    /**
     * 判断是否是邮编地址
     * @param zipCode
     * @return
     */
    public static boolean isZipCode(String zipCode) {
        return StringUtils.isBlank(zipCode) ? false : ZIP_CODE_PATTERN.matcher(zipCode).matches();
    }
    /**
	 * 
	* @Title:
	* @Description: 截取除去IP外的URL(不包括请求参数串)
	* @param url
	* @return    
	* @return String
	* @throws
	 */
	public static String parseUrl(String url){
    	url=url.replaceAll (URL_CUT, "$1");
    	Integer index=url.indexOf("/");
    	String urldata=url.substring(index);
		return urldata;
		
	}
	public static void main(String[] args) {
		String url="http://test.open.youxiduo.com:18080/module_guild/get_guild_count";
		String url1="http://121.40.78.19:18080/module_control/gift/get_gift";
		String cutUrl=parseUrl(url);
		String cutUrl1=parseUrl(url1);
		System.out.println(cutUrl);
		System.out.println(cutUrl1);
	}
}
